package laobeizi;

public class toCase {
    public static String _toUpperCase(String str)
    {
        if(str == null) return null;
        StringBuilder result = new StringBuilder();
        for(char ch :str.toCharArray())
        {
            if(ch >= 'a' && ch <= 'z')
            {
                result.append((char) (ch - ('a' - 'A')));
            }
            else
            {
                result.append(ch);
            }
        }
        return result.toString();
    }

    public static String _toLowerCase(String str)
    {
        if(str == null) return null;
        StringBuilder result = new StringBuilder();
        for(char ch :str.toCharArray())
        {
            if(ch >= 'A' && ch <= 'Z')
            {
                result.append((char) (ch - ('A' - 'a')));
            }
            else
            {
                result.append(ch);
            }
        }
        return result.toString();
    }

    public static void main(String[] args) {
        String input = "Hello World!";
        System.out.println("original: " + input);
        System.out.println("toUpperCase: " + _toUpperCase(input));
        System.out.println("toLowerCase: " + _toLowerCase(input));
    }
}
